package cn.poka.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.ljsw.activity.R;

import java.util.HashMap;
import java.util.Map;


public class SoundUtil {

	public static SoundPool sp ;
	public static Map<Integer, Integer> suondMap;
	public static Context context;

	//��ʼ��������
	public static void initSoundPool(Context context){
		SoundUtil.context = context;
		sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 1);
		suondMap = new HashMap<Integer, Integer>();
		suondMap.put(1, sp.load(context, R.raw.msg, 1));
	}

	public static  void play(int sound, int number){
		AudioManager am = (AudioManager)SoundUtil.context.getSystemService(SoundUtil.context.AUDIO_SERVICE);
		//���ص�ǰAlarmManager�������
		float audioMaxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

		//���ص�ǰAudioManager���������ֵ
		float audioCurrentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
		float volumnRatio = audioCurrentVolume/audioMaxVolume;
		sp.play(
				suondMap.get(sound), //���ŵ�����Id
				audioCurrentVolume, //����������
				audioCurrentVolume, //����������
				1, //���ȼ���0Ϊ���
				number, //ѭ��������0�޲�ѭ����-1����Զѭ��
				1);//�ط��ٶȣ�ֵ��0.5-2.0֮�䣬1Ϊ�����ٶ�
	}


	public void play(){
		SoundPool soundPool= new SoundPool(10,AudioManager.STREAM_SYSTEM,5);
		soundPool.load(context,R.raw.msg,1);
		soundPool.play(1,1, 1, 0, 0, 1);
	}

}
